<!--
 * @Author: your name
 * @Date: 2021-05-25 13:13:17
 * @LastEditTime: 2021-05-26 17:47:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \遵义\zunyi\src\components\navBar.vue
-->
<template>
  <div>
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      router
    >
      <el-menu-item index="/home">首页</el-menu-item>
      <el-menu-item index="/signup">我的报名</el-menu-item>
      <el-menu-item index="/certificate">我的证书</el-menu-item>
      <el-menu-item index="/user">我的信息</el-menu-item>
      <div class="el-menu-demo-right">
        <!-- 类型，尺寸，地址 -->
        <el-avatar shape="square" :size="45" class="top-right-img"></el-avatar>
        <el-dropdown>
          <span class="el-dropdown-link">
            用户名<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: "/home",
    };
  },
  methods: {
    logout() {
      console.log("退出了");
    },
  },
  watch: {
      "$route":{
          handler(val){
              this.activeIndex= val.path
          },
          immediate:true,
          deep:true
      }
  },
};
</script>

<style lang="scss" scoped>
html,body{
  display: flex;
}
.el-menu-demo {
  position: relative;
  width: 1200px;
  margin: 0 auto;
  .el-menu-demo-right {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    right: 60px;
    .top-right-img {
      margin-right: 15px;
    }
  }
}
</style>
